from salary import settings
from django.core.mail import EmailMultiAlternatives, send_mail,send_mass_mail   # send_mass_mail一个连接发送多个邮件
from login.models import Department


# 根据传入的部门ID，获取此部门的所有下属部门，返回ID
def getAllSubDept(did):
    all_dept = list()
    all_dept.append(did)
    # 1,获取下级部门
    data = Department.objects.filter(pid=did).all()
    if data:
        # 有下属部门
        for j in data:
            # 将所有的子部门加入
            all_dept.append(j.id)
            # 开始检查是否有2级子部门
            data_2 = Department.objects.filter(pid=j.id).all()
            if data_2:
                # 有二级下属部门
                for x in data_2:
                    all_dept.append(x.id)
                    # 开始检查是否有3级子部门
                    data_3 = Department.objects.filter(pid=x.id).all()
                    if data_3:
                        # 有三级子部门
                        for h in data_3:
                            all_dept.append(h.id)
                            # 开始检查4级子部门
                            data_4 = Department.objects.filter(pid=h.id).all()
                            if data_4:
                                # 有4级子部门
                                for k in data_4:
                                    all_dept.append(k.id)
                                    # 开始检查5级子部门
                                    data_5 = Department.objects.filter(pid=k.id).all()
                                    if data_5:
                                        for u in data_5:
                                            all_dept.append(u.id)
    # 连续5级下属部门处理完毕
    return all_dept
